home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / libusg / fopenexcl.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  383b  |  21 lines

  1. /*
  2.  * fopenexcl(name) - fopen(name, "w") with error if name exists (USG)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <fcntl.h>
  8.  
  9. FILE *
  10. fopenexcl(name)
  11. register char *name;
  12. {
  13.     /* This is the cheaper way. */
  14.     register int fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0666);
  15.  
  16.     if (fd < 0)
  17.         return NULL;        /* name existed or couldn't be made */
  18.     else
  19.         return fdopen(fd, "w");
  20. }
  21.